﻿<phone:PhoneApplicationPage 
    x:Class="BookCaching.Pages.BookListPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:customControls="clr-namespace:BookCaching.CustomControls"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
    shell:SystemTray.IsVisible="True"
    DataContext="">
    
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="bookItemTemplate">
                <customControls:GridID Tap="BookItemTemplate_Tap" ID="{Binding ID}">
                    <customControls:GridID.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                    </customControls:GridID.ColumnDefinitions>                
                    <Image Grid.Row="0"
                           Grid.Column="0"
                           Height="70"
                           Width="50" 
                           Source="{Binding CoverImagePath}" 
                           Visibility="{Binding ImageThumbnailVisibility}"/>
                    <TextBlock Grid.Row="0"
                               Grid.Column="1"
                               TextWrapping="NoWrap"
                               FontSize="40"
                               Text="{Binding Title}"
                               Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" />
                </customControls:GridID>
        </DataTemplate>        

        <DataTemplate x:Key="groupItemTemplate">
            <Border Background="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" 
                    Width="99" 
                    Height="99" 
                    Margin="6">
                <TextBlock Text="{Binding Title}" 
                           FontSize="40" 
                           Foreground="{Binding Source={StaticResource CurrentSettings}, Path=BackgroundColor, Mode=TwoWay}" />
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="groupHeaderTemplate">
            <Border Background="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" 
                    Margin="6">
                <TextBlock Text="{Binding Title}" 
                           FontSize="40" 
                           Foreground="{Binding Source={StaticResource CurrentSettings}, Path=BackgroundColor, Mode=TwoWay}" />
            </Border>
        </DataTemplate>

    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{Binding Source={StaticResource CurrentSettings}, Path=BackgroundColor, Mode=TwoWay}">

        <controls:Pivot>
            <controls:Pivot.Title>
                <TextBlock Text="{Binding ConverterParameter=ApplicationTitle, Converter={StaticResource LocalizedStrings}, Source={StaticResource LocalizedStrings}}"
                           Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" />
            </controls:Pivot.Title>
            <!--Pivot item one-->
            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="{Binding ConverterParameter=FoundBooksListTitle, Converter={StaticResource LocalizedStrings}, Source={StaticResource LocalizedStrings}}"
                               Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" />
                </controls:PivotItem.Header>
                <Grid x:Name="foundBooksGrid" Margin="12,0,12,0">
                    <toolkit:LongListSelector x:Name="foundBooksLongListSelector"
                                              ItemTemplate="{StaticResource bookItemTemplate}"
                                              GroupHeaderTemplate="{StaticResource groupHeaderTemplate}"
                                              GroupItemTemplate="{StaticResource groupItemTemplate}"
                                              Background="{Binding Source={StaticResource CurrentSettings}, Path=BackgroundColor, Mode=TwoWay}"
                                              Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}">
                        <toolkit:LongListSelector.GroupItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel />
                            </ItemsPanelTemplate>
                        </toolkit:LongListSelector.GroupItemsPanel>
                    </toolkit:LongListSelector>
                </Grid>
            </controls:PivotItem>

            <!--Pivot item two-->
            <controls:PivotItem>
                <controls:PivotItem.Header>
                    <TextBlock Text="{Binding ConverterParameter=AddedBooksListTitle, Converter={StaticResource LocalizedStrings}, Source={StaticResource LocalizedStrings}}"
                               Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}" />
                </controls:PivotItem.Header>
                <Grid x:Name="addedBooksGrid" Margin="12,0,12,0">
                    <toolkit:LongListSelector x:Name="addedBooksLongListSelector"
                                    ItemTemplate="{StaticResource bookItemTemplate}"
                                    GroupHeaderTemplate="{StaticResource groupHeaderTemplate}"
                                    GroupItemTemplate="{StaticResource groupItemTemplate}"
                                              Background="{Binding Source={StaticResource CurrentSettings}, Path=BackgroundColor, Mode=TwoWay}"
                                              Foreground="{Binding Source={StaticResource CurrentSettings}, Path=ForegroundColor, Mode=TwoWay}">
                        <toolkit:LongListSelector.GroupItemsPanel>
                            <ItemsPanelTemplate>
                                <toolkit:WrapPanel />
                            </ItemsPanelTemplate>
                        </toolkit:LongListSelector.GroupItemsPanel>
                    </toolkit:LongListSelector>
                </Grid>
            </controls:PivotItem>
        </controls:Pivot>                
    </Grid>
 
    <!--Sample code showing usage of ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton x:Name="findBookButton" 
                                            Click="FindBookButton_Click" 
                                            IconUri="/Images/AppbarIcons/appbar.add.rest.png" 
                                            Text="Button 1" />
            <shell:ApplicationBarIconButton x:Name="settingsApplicationBarButton" 
                                            Click="SettingsApplicationBarButton_Click" 
                                            IconUri="/Images/AppbarIcons/appbar.feature.settings.rest.png" 
                                            Text="Button 2" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>
